package com.easpeed.elevator.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.util.Log;
import com.bigyu.utils.Logger;

import java.io.File;

public class UpdateReceiver  extends BroadcastReceiver {

    public static final String APK_FILE_PATH = Environment.getExternalStorageDirectory() + "/download/"+"release.apk";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
            Logger.e("oye","install" + "安装了完成:" + "包名的程序");
            File file = new File(APK_FILE_PATH);
            if (file.exists() && file.isFile()) {
                Logger.e("oye","install" + "删除了文件:" + APK_FILE_PATH);
                file.delete();
            } else {
                Logger.e("oye","install" + "文件不存在:" + APK_FILE_PATH);
            }
            Intent intent1 = context.getPackageManager().getLaunchIntentForPackage("com.easpeed.elevator");
            context.startActivity(intent1);
        }
        //接收安装广播
        if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
            String packageName = intent.getDataString();
            Logger.e("oye","install" + "安装了:" + packageName + "包名的程序");

        }
        //接收卸载广播
        if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
            String packageName = intent.getDataString();
            Logger.e("oye","install" + "卸载了:" + packageName + "包名的程序");
        }
    }
}
